﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HNCDataSetTableAdapters;

public partial class UserControl_content_product_top : System.Web.UI.UserControl
{
    CategoryTableAdapter cate = new CategoryTableAdapter();
    ProductsTableAdapter pro = new ProductsTableAdapter();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ltrProductTop.Text = LoadTopProduct();
        }
    }
    public string LoadTopProduct()
    {
        string str = "";
        DataTable dt = cate.GetCateByParentID(3);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            int CateID = int.Parse(dt.Rows[i]["CateID"].ToString());
            DataTable dt2 = pro.GetProductByCateIDTop(1000, CateID);
            for (int j = 0; j < dt2.Rows.Count; j++)
            {
                string ProductID = dt2.Rows[j]["ProductID"].ToString();
                string Image = dt2.Rows[j]["Image"].ToString();
                string Title = FuntionHNC.Catchuoi(dt2.Rows[j]["Title"].ToString(), 15);
                string Content = FuntionHNC.Catchuoi(FuntionHNC.RemoveHtmlTagsUsingCharArray(dt2.Rows[j]["Content"].ToString()), 25);


                str += "<div class=\"da-slide\">";
                str += "<h2>" + Title + "</h2>";
                str += "<p> " + Content + "</p>";
                str += "<a class=\"da-link\" href=\"chi-tiet-san-pham-" + ProductID + ".html\">Chi tiết</a>";
                str += "<div class=\"da-img\">";              
                str += "<img height=\"256px\" width=\"256px\" src=\"UserUploads/Product/" + Image + "\"/></div></div>";
            }
        }
        return str;
    }
}